package jbox2dprocessing.compontent;

import org.jbox2d.collision.CircleDef;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.BodyDef;

import pbox2d.PBox2D;
import processing.core.PConstants;

public class BaseCircle extends AbstractBox2DShape {
	
	public float baseRadius;
	
	
	public BaseCircle(PBox2D _box2d, int _master) {
		super(_box2d);
		this.baseRadius = 20;
		this.master = _master;
		makeBaseBody(baseRadius, new Vec2(baseX, baseY));
	}

	public BaseCircle(PBox2D _box2d, int _master, float baseDensity) {
		super(_box2d, baseDensity);
		this.baseRadius = 20;
		this.master = _master;
		makeBaseBody(baseRadius, new Vec2(baseX, baseY));
	}

	public BaseCircle(float baseX, float baseY, float baseRadius, PBox2D _box2d, int _master) {
		super(baseX, baseY, _box2d);
		this.baseRadius = baseRadius;
		this.master = _master;
		makeBaseBody(baseRadius, new Vec2(baseX, baseY));
		// TODO Auto-generated constructor stub
	}

	public BaseCircle(float baseX, float baseY, float baseRadius, PBox2D _box2d, int _master,
			float baseDensity, float baseFriction, float baseRestitution) {
		super(baseX, baseY, _box2d, baseDensity, baseFriction, baseRestitution);
		this.baseRadius = baseRadius;
		this.master = _master;
		makeBaseBody(baseRadius, new Vec2(baseX, baseY));
		// TODO Auto-generated constructor stub
	}

	public BaseCircle(float baseX, float baseY, float baseRadius, PBox2D _box2d, int _master, int baseColor,
			int baseStrokeColor, int baseStrokeWeight, float baseDensity,
			float baseFriction, float baseRestitution) {
		super(baseX, baseY, _box2d, baseColor, baseStrokeColor,
				baseStrokeWeight, baseDensity, baseFriction, baseRestitution);
		
		this.baseRadius = baseRadius;
		this.master = _master;
		makeBaseBody(baseRadius, new Vec2(baseX, baseY));
		// TODO Auto-generated constructor stub
	}
	
	public void makeBaseBody(float _r, Vec2 center){
		CircleDef cd = new CircleDef();
		cd.radius = box2d.scaleScreenToWorld(_r);
		
		cd.density = baseDensity;
		cd.friction = baseFriction;
		cd.restitution = baseRestitution;
		
		BodyDef bd = new BodyDef(this.master);
		bd.position.set(box2d.screenToWorld(center));
		
		baseBody = box2d.createBody(bd);
		baseBody.createShape(cd);
		baseBody.setMassFromShapes();
	}
	
	public void display(){
		Vec2 pos = box2d.getScreenPos(baseBody);
		float a = baseBody.getAngle();
		
		parent.ellipseMode(PConstants.CENTER);
		parent.pushMatrix();
		parent.translate(pos.x, pos.y);
		parent.rotate(PConstants.PI - a);
		parent.fill(baseColor);
		parent.stroke(baseStrokeColor);
		parent.strokeWeight(baseStrokeWeight);
		parent.ellipse(0, 0, baseRadius*2, baseRadius*2);
		parent.line(0, 0, baseRadius, 0);
		parent.popMatrix();
	}

}
